/*
 * @Author: EvanXU evanxu8023@163.com
 * @Date: 2023-02-04 11:02:16
 * @LastEditors: Evanxu-home evanxu8023@163.com
 * @LastEditTime: 2025-11-16 11:15:27
 * @FilePath: \program\applications\user_memory.h
 * @Description: 
 *  xxx 
 * Copyright (c) 2023 by EvanXU evanxu8023@163.com, All Rights Reserved. 
 */
#ifndef user_memory_h
#define user_memory_h

/* 包含头文件 ----------------------------------------------------------------*/
#include "define.h"
#include "drv_usart.h"
#include "drv_flash.h"

/* 宏定义  ------------------------------------------------------------------*/
/* 系统参数保存内部FLASH起始地址, 总空间为4KByte */
#define USER_MEMORY_START_ADDR              (0x08000000 + (uint32_t)190*1024)

/* 用户配置参数数据包包头，用于识别参数是否存在 */
#define USER_MEMEORY_DATA_HEAD              0xAABBCC87

/* 类型定义 ------------------------------------------------------------------*/
struct user_mem
{
	u32 head;                                       /* 数据包头 */
	SYS_CFG  cfg_para;                              /* 系统配置参数 */
    u32     crc;                                    /* CRC和校验值 */
};
typedef struct user_mem		USER_MEMORY;

/* 系统默认配置数据 */
#define USER_MEMORY_DEFAULT														\
		{																		\
			.head 									=	USER_MEMEORY_DATA_HEAD,	\
            .cfg_para.rgb_length                    =	10,                     \
            .cfg_para.flow_time                     =	5*1000,                 \
            .cfg_para.all_on_time                   =	3*1000,                 \
            .cfg_para.rgb_bright                    =	80,                     \
            .cfg_para.rgb_format                    =	RGB_FORMAT_GRB,			\
        }



/* 系统运行参数 */
extern USER_MEMORY sys_user_memory;

int read_user_config_para(void);
void write_user_config_para(USER_MEMORY *buff);
void reset_user_config_para(void);

uint32_t user_memory_para_crc_check(uint32_t *buff, uint32_t len);

#endif




